/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeanViews;

import entity.Category;
import entity.Complaint;
import entity.Members;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import processor.CategoryFacade;
import processor.ComplaintFacade;

/**
 *
 * @author maynoigi
 */
@ManagedBean
@SessionScoped
public class SubmitComplaint {
    @EJB
    private CategoryFacade categoryFacade;
    @EJB
    private ComplaintFacade complaintFacade;

    @ManagedProperty(value = "#{login}")//this is EL name of your bean 
    private Login injectedBean;
    private LinkedHashMap<String,String> categorys=new LinkedHashMap<String,String>();
    private String categorySelected;
    private String title;
    private String content;
    public String getCategorySelected() {
        return categorySelected;
    }

    public void setCategorySelected(String categorySelected) {
        this.categorySelected = categorySelected;
    }
 
    
    public Login getInjectedBean() {
        return injectedBean;
    }

    public void setInjectedBean(Login injectedBean) {
        this.injectedBean = injectedBean;
    }

    public LinkedHashMap<String,String> getCategorys() {
        List<Category> temp=categoryFacade.getCategoryAll();
        for (Category category : temp) {
            categorys.put(category.getCategoryName(), category.getCategoryPriority()+","+category.getCategoryID());
        }
        return categorys;
    }

    public void setCategorys(LinkedHashMap<String,String> categorys) {
        this.categorys = categorys;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
    public SubmitComplaint() {
    }
    
    public String submitComplaints()
    {
        String category[]=categorySelected.split(",");
     
        Category a=new Category();
        a.setCategoryID(Integer.parseInt(category[1]));
        Complaint temp=new Complaint();
        temp.setCategoryID(a);
        temp.setComplaintPriority(category[0]);
        temp.setComplaintContent(content);
        temp.setComplaintStatus(0);
        temp.setComplaintTitle(title);
        temp.setMembersID(injectedBean.getCustomer());
        temp.setDepartmentID(injectedBean.getCustomer().getDepartmentID());
        temp.setComplaintCreateDate(new Date());
        complaintFacade.create(temp);
  
        return "Report.jsp";
    }
}
